﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses

Public Class TourDetails
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Request.QueryString("tid") Is Nothing Then
                Fill_dtList(dlTours, "select * from ptn_Countries")
                plTourList.Visible = True
                plTourDetails.Visible = False
            Else
                plTourList.Visible = False
                plTourDetails.Visible = True
                fillTour(Request.QueryString("tid"))
                Fill_dtList(dlImages, "select g.* from ptn_Gallery g inner join ptn_TourGallery tg on tg.GalleryId=g.Id where IsActive=1 and tg.TourId=" & Request.QueryString("tid"))
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub fillTour(ByVal ID As Integer)
        Dim strOutput As New StringBuilder
        'Dim strSql As String
        'Dim txt As Array
        Dim dt As New DataTable

        'strSql = "SELECT [Id],[CategoryId],[ZoneId],[Name],[TourCode],[Days],[Nights],[Summary],[Description],[Include],[Exclude],[Cost],[MealType],"
        'strSql += "[Thumbnail],[GMap],[MetaTitle],[MetaKeywords],[MetaDescription],[IsFeatured],[IsPackage],[IsCruise],[IsSafari],[IsShortBreak],[IsActive],
        'strSql += "[Vieworder],[CreatedOn],[UpdatedOn],"
        'strSql += "(select Name from ptn_Category where Id=CategoryId) as CatName,"
        'strSql += "(select Name from ptn_Zones where Id=ZoneId) as ZoneName from ptn_tours"
        'strSql += "where IsActive=1 and id=@Id and ((@Type='P' and IsPackage=1) or (@Type='C' and IsCruise=1)"
        'strSql += "or (@Type='S' and IsSafari=1) or (@Type='SB' and IsShortBreak=1))"

        'dt = Fill_Table("exec fillTour " & Id & ", 'P'", "Tours")
        dt = Fill_Table("select * from ptn_Tours where Id=" & ID, "Tours")

        For Each dr As DataRow In dt.Rows
            'strOutput.Append("<h4><em>Cities Included:</em> " & dr.Item("Summary").ToString & "</h4>")
            'strOutput.Append("<div class=""description"">" & dr.Item("Description").ToString & "</div>")
            'ltrDescription.Text = strOutput.ToString
            ltrTitle.Text = dr.Item("Name")
            ltrDescription.Text = "<h4><em>Cities Included:</em> " & dr.Item("Summary").ToString & "</h4>"
            ltrDescription.Text += "<div class=""description"">" & dr.Item("Description").ToString & "</div>"


            ltrIncludes.Text = "<p><strong>The tour included:</strong></p>"
            ltrIncludes.Text += "<p>" & dr.Item("Include").ToString & "</p>"
            ltrIncludes.Text += "<p><strong>The tour excluded:</strong></p>"
            ltrIncludes.Text += "<p>" & dr.Item("Exclude").ToString & "</p>"

            ltrCost.Text = getCost(ID, "B2B")
        Next
    End Sub

    Private Function getCost(ByVal Id As Integer, ByVal Client As String)
        Dim strOutput As New StringBuilder
        Dim dtCost As DataTable
        Dim count As Integer = 0
        dtCost = Fill_Table("select top 1 [Id],[TourId],[Pax_1],[Pax_2],[Pax_3],[Pax_4],[Pax_5],[Pax_6],[Pax_7],[Pax_8],[Pax_9],[Pax_Child],[Single_Supp],CONVERT(VARCHAR(10), [StartDate], 103) [StartDate],CONVERT(VARCHAR(10), [EndDate], 103) [EndDate] from ptn_TourCost where Tourid=" & Id & " and ClientType='" & Client & "' and (getdate() between startdate and enddate) order by startdate desc, enddate desc", "TourCost")

        For Each drCost As DataRow In dtCost.Rows
            If drCost.Item("Pax_1").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>1 Pax</strong> - " & formatPrice(drCost.Item("Pax_1").ToString) & "</div>")
            End If
            If drCost.Item("Pax_2").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>2 Pax</strong> - " & formatPrice(drCost.Item("Pax_2").ToString) & "</div>")
            End If
            If drCost.Item("Pax_3").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>3 Pax</strong> - " & formatPrice(drCost.Item("Pax_3").ToString) & "</div>")
            End If
            If drCost.Item("Pax_4").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>4 pax</strong> - " & formatPrice(drCost.Item("Pax_4").ToString) & "</div>")
            End If
            If drCost.Item("Pax_5").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>5 pax</strong> -  " & formatPrice(drCost.Item("Pax_5").ToString) & "</div>")
            End If
            If drCost.Item("Pax_6").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>6 pax</strong> -  " & formatPrice(drCost.Item("Pax_6").ToString) & "</div>")
            End If
            If drCost.Item("Pax_7").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>7 pax</strong> -  " & formatPrice(drCost.Item("Pax_7").ToString) & "</div>")
            End If
            If drCost.Item("Pax_8").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>8 pax</strong> - " & formatPrice(drCost.Item("Pax_8").ToString) & "</div>")
            End If
            If drCost.Item("Pax_9").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>9 pax</strong> - " & formatPrice(drCost.Item("Pax_9").ToString) & "</div>")
            End If
            If drCost.Item("Single_Supp").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>Single Supp</strong> - " & formatPrice(drCost.Item("Single_Supp").ToString) & "</div>")
            End If
            If drCost.Item("Pax_Child").ToString <> 0 Then
                strOutput.Append("<div class=""costbox""><strong>Child 0-10</strong> - " & formatPrice(drCost.Item("Pax_Child").ToString) & "</div>")
            End If
            strOutput.Append("<div class=""clear""></div><div class=""valid clearfix"">Valid upto: " & drCost.Item("EndDate").ToString & "</div>")
            count = count + 1
        Next
        If count = 0 Then

            Dim strSub As String
            If Not Request.QueryString("tId") Is Nothing Then
                Dim txt As Array
                txt = RetriveData("select Name, TourCode, Days, Nights from ptn_Tours where Id=" & Request.QueryString("tId"), 3)
                strSub = txt(0) & " - " & txt(1) & " (" & txt(2) & " Days/" & txt(3) & "Nights)"
            Else
                strSub = "Tour"
            End If

            strOutput.Append("<div class=""subhead clearfix"">Send a Request on <a href=""mailto:enquiry@philatourism.com?Subject=Request for " & strSub & """>enquiry@philatourism.com</a></div>")
        End If
        Return strOutput.ToString
    End Function


End Class